package com.example.mapper;

import com.example.entity.CartInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author 朽
*/
public interface CartInfoMapper extends BaseMapper<CartInfo> {

    @Select("SELECT id, user_id, sku_id, `check`, count, sale_attrs FROM cart_info WHERE user_id = #{userId}")
    List<CartInfo> getAllByUserId(Long userId);

    @Delete("DELETE FROM cart_info WHERE user_id = #{userId}")
    int deleteCart(Long userId);

    @Delete("DELETE FROM cart_info WHERE user_id = #{userId} and sku_id = #{skuId}")
    int deleteItemBySkuId(Long userId, Long skuId);

    @Insert("INSERT INTO cart_info (user_id, sku_id, `check`, count, sale_attrs) VALUES (#{userId}, #{skuId}, #{check}, #{count}, #{saleAttrs})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertCartInfo(CartInfo cartInfo);

    @Update("UPDATE cart_info SET count = #{count}, `check` = #{check} WHERE id = #{id}")
    int updateCartInfo(Long id, Integer count, Integer check);

}




